/*
 * Copyright (c) 2010, Katholieke Universiteit Leuven
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice,
 *       this list of conditions and the following disclaimer in the documentation
 *       and/or other materials provided with the distribution.
 *     * Neither the name of the Katholieke Universiteit Leuven nor the names of
 *       its contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef __LOOCI_GWAPI_RUNTIME_CONTROL_H__
#define __LOOCI_GWAPI_RUNTIME_CONTROL_H__

#include <stdbool.h>
#include <inttypes.h>
#include "common.h"

/**
 * Deactivate a component.
 *
 * @param componentID The identifier of the component to deactivate.
 * @param nodeID The identifier of the node (IPv6 address) on which to  
 *               deactivate the component.
 *
 * @return True if the deactivation was successful, false otherwise.
 */
bool looci_deactivate(uint8_t componentID, char * nodeID);

/**
 * Reactivate a component.
 *
 * @param componentID The identifier of the component to reactivate.
 * @param nodeID The identifier of the node (IPv6 address) on which to 
 *               reactivate the component.
 *
 * @return True if the reactivation was successful, false otherwise.
 */
bool looci_activate(uint8_t componentID, char * nodeID);

/**
 * Reset the wirings of a component.
 *
 * @param componentID The identifier of the component to reset the wiring of.
 * @param nodeID The identifier of the node (IPv6 address) on which to 
 *               the component resides.
 *
 * @return True if the reset was successful, false otherwise.
 */
bool looci_reset_wirings(uint8_t componentID, char * nodeID);

/**
 * Wire two specific components on the same node.
 *
 * @param interfaceEvent The event type at the source.
 * @param sourceComponentID The component identifier at the source.
 * @param receptacleEvent The event type at the destination.
 * @param destComponentID The component identifier at the destination.
 * @param nodeID The node identifier of the node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_wire_local(uint8_t interfaceEvent, uint8_t sourceComponentID, 
    uint8_t receptacleEvent, uint8_t destComponentID, char * nodeID);

/**
 * Start delivering a certain type of events (regardles of the source node) to a certain receptacle.
 *
 * @param interfaceEvent The event type at the source.
 * @param receptacleEvent The event type at the destination.
 * @param destComponentID The component identifier at the destination.
 * @param destNodeID The node identifier of the destination node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_wire_from_all(uint8_t interfaceEvent, uint8_t receptacleEvent, uint8_t destComponentID, char * destNodeID);

/**
 * Send events published at a specific interface to the broadcast address.
 *
 * @param interfaceEvent The event type to broadcast.
 * @param sourceComponentID The component identifier of the event source.
 * @param sourceNodeID The identifier of the source node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_wire_to_all(uint8_t interfaceEvent, uint8_t sourceComponentID, char * sourceNodeID);

/**
 * Send events published at a specific interface to a specific node.
 * This doesn't affect the destination node (see looci_wire_from for that).
 *
 * @param interfaceEvent The event type at the source.
 * @param sourceComponentID The component identifier at the source.
 * @param sourceNodeID The identifier of the source node (IPv6 address).
 * @param destNodeID The node identifier of the destination node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_wire_to(uint8_t interfaceEvent, uint8_t sourceComponentID, char * sourceNodeID, char * destNodeID);

/**
 * Start delivering events produced at a specific interface to a specific receptacle.
 * This doesn't affect the source node (see looci_wire_to for that).
 *
 * @param interfaceEvent The event type at the source.
 * @param sourceComponentID The component identifier at the source.
 * @param sourceNodeID The identifier of the source node (IPv6 address).
 * @param receptacleEvent The event type at the destination.
 * @param destComponentID The component identifier at the destination.
 * @param destNodeID The node identifier of the destination node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_wire_from(uint8_t interfaceEvent, uint8_t sourceComponentID, char * sourceNodeID, 
    uint8_t receptacleEvent, uint8_t destComponentID, char * destNodeID);

/**
 * Unwire two specific components on the same node.
 *
 * @param interfaceEvent The event type at the source.
 * @param sourceComponentID The component identifier at the source.
 * @param receptacleEvent The event type at the destination.
 * @param destComponentID The component identifier at the destination.
 * @param nodeID The node identifier of the node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_unwire_local(uint8_t interfaceEvent, uint8_t sourceComponentID,
    uint8_t receptacleEvent, uint8_t destComponentID, char * nodeID);

/**
 * Stop delivering certain types of events (regardless of the source node) to a component.
 *
 * @param interfaceEvent The event type at the source.
 * @param receptacleEvent The event type at the destination.
 * @param destComponentID The component identifier at the destination.
 * @param destNodeID The node identifier of the destination node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_unwire_from_all(uint8_t interfaceEvent, uint8_t receptacleEvent, uint8_t destComponentID, char * destNodeID);

/**
 * Stop sending events published at a specific interface to the broadcast address.
 *
 * @param interfaceEvent The event type to broadcast.
 * @param sourceComponentID The component identifier of the event source.
 * @param sourceNodeID The identifier of the source node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_unwire_to_all(uint8_t interfaceEvent, uint8_t sourceComponentID, char * sourceNodeID);

/**
 * Stop sending events published at a specific interface to a specific node
 * This doesn't affect the destination node.
 *
 * @param interfaceEvent The event type at the source.
 * @param sourceComponentID The component identifier at the source.
 * @param sourceNodeID The identifier of the source node (IPv6 address).
 * @param destNodeID The node identifier of the destination node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_unwire_to(uint8_t interfaceEvent, uint8_t sourceComponentID, char * sourceNodeID, char * destNodeID);

/**
 * Stop delivering events produced at a specific interface to a specific receptacle.
 * This doesn't affect the source node.
 *
 * @param interfaceEvent The event type at the source.
 * @param sourceComponentID The component identifier at the source.
 * @param sourceNodeID The identifier of the source node (IPv6 address).
 * @param receptacleEvent The event type at the destination.
 * @param destComponentID The component identifier at the destination.
 * @param destNodeID The node identifier of the destination node (IPv6 address).
 *
 * @return True if successful, false otherwise.
 *
 * @TODO Should this be something else than uint8_t for event types.
 */
bool looci_unwire_from(uint8_t interfaceEvent, uint8_t sourceComponentID, char * sourceNodeID, 
    uint8_t receptacleEvent, uint8_t destComponentID, char * destNodeID);

#endif //__LOOCI_GWAPI_RUNTIME_CONTROL_H__
